﻿    #region $ID$ event handlers
    
    protected void $ID$_Init(object sender, EventArgs e)
    {
        GridView aGRV = (GridView)sender;
        
        aGRV.AllowPaging=true ;
        aGRV.PageSize=$PageSize$;
        aGRV.AutoGenerateColumns = false;
        aGRV.DataKeyNames=new string[] {$DataKeyNames$};

        // validate requiredment before action
        aGRV.RowUpdating += new GridViewUpdateEventHandler($ID$_RowUpdating);
        aGRV.RowDeleting += new GridViewDeleteEventHandler($ID$_RowDeleting);

        // handle aODS.UpdateMethod and aODS.DeleteMethod Exception
        aGRV.RowUpdated += new GridViewUpdatedEventHandler($ID$_RowUpdated);
        aGRV.RowDeleted += new GridViewDeletedEventHandler($ID$_RowDeleted);
    }

    /// <summary>
    /// 用於在刪除資料前判斷輸入資料是否有效 (若無效，e.Cancel = true)
    /// </summary>
    private void $ID$_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
    }

	/// <summary>
    /// 用於在異動資料前判斷輸入資料是否有效(若無效，e.Cancel = true)
    /// </summary>
    private void $ID$_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
    }
    
    /// <summary>
    /// 用於在刪除資料後判斷刪除是否成功
    /// </summary>
    private void $ID$_RowDeleted(object sender, GridViewDeletedEventArgs e)
    {
        if (e.Exception != null)
        {
            Log.ReportError(e.Exception.InnerException);
            e.ExceptionHandled = true;
        }
        else
        {
            (sender as GridView).DataBind();
        }
    }

    /// <summary>
    /// 用於在異動資料前判斷輸入資料是否有效
    /// </summary>
    private void $ID$_RowUpdated(object sender, GridViewUpdatedEventArgs e)
    {
        if (e.Exception != null)
        {
            Log.ReportError(e.Exception.InnerException);
            e.KeepInEditMode = true;
            e.ExceptionHandled = true;
        }
        else
        {
            (sender as GridView).DataBind();
        }
    }

    #endregion